{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import subprocess\n",
    "from pathlib import Path\n",
    "import sys\n",
    "sys.path.append(\"../ai-sdr\")\n",
    "from Data.opnr import find_data\n",
    "from Data.rawdata import ChannelizedData\n",
    "from NR.gscn import GSCN2CentFreq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "init = False\n",
    "clear = True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"900.0\"\n",
    "# center_f = 874.2e6\n",
    "# decimate_factor = 64\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"2565.0\"\n",
    "# center_f = GSCN2CentFreq(6312)\n",
    "# decimate_factor = 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"3450.0\"\n",
    "# center_f = GSCN2CentFreq(7783)\n",
    "# decimate_factor = 8\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"1850.0\"\n",
    "# center_f = 1835.6e6\n",
    "# decimate_factor = 64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"1950.0\"\n",
    "# center_f = 1935.6e6\n",
    "# decimate_factor = 64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"2050.0\"\n",
    "# center_f = 2035.6e6\n",
    "# decimate_factor = 64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"2150.0\"\n",
    "# center_f = 2140e6\n",
    "# decimate_factor = 64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"1900.0\"\n",
    "# center_f = 1895e6\n",
    "# decimate_factor = 64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"2250.0\"\n",
    "# center_f = 2235.6e6\n",
    "# decimate_factor = 64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"2350.0\"\n",
    "# center_f = 2335.6e6\n",
    "# decimate_factor = 64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"2650.0\"\n",
    "# center_f = 2635.6e6\n",
    "# decimate_factor = 64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# capture_f = \"750.0\"\n",
    "# center_f = GSCN2CentFreq(1955)\n",
    "# decimate_factor = 16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "capture_f = \"1050.0\"\n",
    "center_f = 1090e6\n",
    "decimate_factor = 32"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "cmd = f\"python3 ../datsrv/capture.py -f {capture_f} -d ../data -a 192.168.1.99\"\n",
    "if init:\n",
    "    cmd += ' -i'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "if clear:\n",
    "    data_p = Path('../data')\n",
    "    for f in data_p.glob('*.sigmf-data'):\n",
    "        f.unlink()\n",
    "    for f in data_p.glob('*.sigmf-meta'):\n",
    "        f.unlink()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "STD:  \n",
      "transmission complete ok\n",
      "End\n",
      "\n"
     ]
    }
   ],
   "source": [
    "proc = subprocess.Popen(\n",
    "    cmd,\n",
    "    stdin=None,\n",
    "    stdout = subprocess.PIPE,\n",
    "    stderr = subprocess.PIPE,\n",
    "    shell = True)\n",
    "outinfo, errinfo = proc.communicate()\n",
    "print(\"STD: \",outinfo.decode('utf-8')[-30:])\n",
    "if len(errinfo)>0:\n",
    "    print(\"ERR: \",errinfo.decode('utf-8'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "fn = find_data('../data',f\"{capture_f}m\")\n",
    "aLTE = ChannelizedData(str(fn))\n",
    "aLTE.channeling(center_f,decimate_factor)\n",
    "aLTE.toDisk()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.11.3 ('venv': venv)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "160761bc1a904adbbd606c3a9b02244365b1a540f860a2c66cbc5cbd24c54900"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
